package com.xingkeduo.business.operation.controller;

import com.xingkeduo.business.operation.domain.ScreenPriceDomain;
import com.xingkeduo.pojo.dto.ScreenPrice.ScreenPriceParm;
import com.xingkeduo.pojo.query.ScreenPriceQuery;
import com.xingkeduo.pojo.vo.ScreenPriceVo;
import com.xingkeduo.tool.ResponseMessage;
import com.xingkeduo.tool.ResponseUtils;
import com.xingkeduo.util.pojo.exception.SystemException;
import com.xingkeduo.util.tool.ReturnUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import static com.xingkeduo.tool.OperaConstants.CMS_URL_PREFIX;

/**
 * 模块管理
 *
 * @author chenxianda <chenxianda@xingkeduo.com>
 * @package BeautyOS 2019年7月19日 11:32:47
 * @copyright Copyright (c) XKD 2019
 */

@Slf4j
@RestController
@RequestMapping(CMS_URL_PREFIX +"/screenPrice")
public class ScreenPriceController extends InitController {

    @Autowired
    private ScreenPriceDomain screenPriceDomain;
    //获取根据店铺ID下单屏信息
    @GetMapping(value = "/getScreenPriceInfo")
    public ResponseUtils getScreenPriceInfo(Long shopId) {
        returnUtil = new ReturnUtil();
        try {
            ScreenPriceVo screenPriceVo = screenPriceDomain.getScreenPriceInfoById(shopId);
            return ResponseUtils.getSuccess(screenPriceVo);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return ResponseUtils.error(throwable.getMessage(), SystemException.Type.DEFAULT.toString());
        }
    }
    //获取下单屏信息
    @GetMapping(value = "/getScreenPriceListInfo")
    public ResponseUtils getScreenPriceListInfo(ScreenPriceQuery screenPriceQuery) {
        returnUtil = new ReturnUtil();
        try {
            List<ScreenPriceVo> screenPriceListInfo = screenPriceDomain.getScreenPriceListInfo(screenPriceQuery);
            return ResponseUtils.getSuccess(screenPriceListInfo);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return ResponseUtils.error(throwable.getMessage(), SystemException.Type.DEFAULT.toString());
        }
    }
    //添加
    @PostMapping("/addScreenPrice")
    public ResponseUtils addScreenPrice(@RequestBody ScreenPriceParm screenPriceParm, ServerHttpRequest request) {

        returnUtil = new ReturnUtil();
        try {
            long operator = this.getOperator(request);
//            long operator = 38;
            log.info("添加下单屏请求参数:{}", screenPriceParm,operator);
            int screenPrice = screenPriceDomain.createScreenPrice(screenPriceParm, operator);
            log.info("添加下单屏返回值:{}", screenPrice);
            return ResponseUtils.getSuccess();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return ResponseUtils.error(throwable.getMessage(), SystemException.Type.DEFAULT.toString());
        }
    }
    //修改
    @PutMapping("updateScreenPrice")
    public String updateScreenPrice(@RequestBody ScreenPriceParm screenPriceParm , ServerHttpRequest request) {
        returnUtil = new ReturnUtil();
        try {
            long operator = this.getOperator(request);
            log.info("修改下单屏请求参数:{}", screenPriceParm,operator);
            ResponseMessage responseMessage = screenPriceDomain.modifyScreenPrice(screenPriceParm, operator);
            log.info("修改下单屏返回值:{}", screenPriceParm,operator);
            return returnUtil.getSuccess();
        } catch (Throwable throwable) {
            return dealException(throwable, returnUtil);
        }
    }

    //初始化脚本
//    @GetMapping(value = "/createScreenScript")
//    public ResponseUtils createScreenScript() {
//        returnUtil = new ReturnUtil();
//        try {
//            int screenScript = screenPriceDomain.createScreenScript();
//            return ResponseUtils.getSuccess(screenScript);
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//            return ResponseUtils.error(throwable.getMessage(), SystemException.Type.DEFAULT.toString());
//        }
//    }


}
